<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>管理用户页面</title>
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <script src="${APP_PATH}/static/js/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet"
          href="${APP_PATH}/static/bootstrap-3.4.1-dist/css/bootstrap.min.css">
    <script
            src="${APP_PATH}/static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 搭建显示页面 -->
<div class="container">
    <!-- 标题行 -->
    <div class="row">
        <div class="col-xs-12">
            <h1>管理员页面</h1>
        </div>
    </div>
    <!-- 按钮 -->
    <!-- <div class="row">
        <div class="col-md-4 col-md-offset-8">
            <button class="btn btn-primary">新增</button>
            <button class="btn btn-danger">删除</button>
        </div>
    </div> -->
    <!-- 显示表格数据 -->
    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover">
                <tr>
                    <th>id</th>
                    <th>name</th>
                    <th>password</th>
                    <th>idcard</th>
                    <th>phone</th>
                    <th>操作</th>
                </tr>
                <c:forEach items="${pageInfo.list }" var="user">
                    <tr>
                        <th>${user.id}</th>
                        <th>${user.name}</th>
                        <th>${user.password}</th>
                        <th>${user.idcard}</th>
                        <th>${user.phone}</th>
                        <th>
                            <button class="btn btn-primary btn-sm">
									<span class="glyphicon glyphicon-pencil" aria-hidden="true">
										编辑 </span>
                            </button>
                            <button class="btn btn-danger btn-sm">
									<span class="glyphicon glyphicon-trash" aria-hidden="true">
										删除 </span>
                            </button>
                            	<button class="btn btn-danger btn-sm" id="down_btn"
									onclick="downloadPass(${user.license})">
									<span class="glyphicon glyphicon-trash" aria-hidden="true">下载
									</span>
								</button>
                        </th>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
    <!-- 分页信息 -->
    <div class="row">
        <!-- 分页文字信息 -->
        <div class="col-md-6">当前${pageInfo.pageNum }页,总${pageInfo.pages }页,总${pageInfo.total }条记录
        </div>
        <!-- 分页条信息 -->
        <div class="col-md-6">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <li><a href="${APP_PATH }/user/selectAll?pn=1">首页</a></li>
                    <c:if test="${pageInfo.hasPreviousPage }">
                        <li><a href="${APP_PATH }/user/selectAll?pn=${pageInfo.pageNum-1}"
                               aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
                        </a></li>
                    </c:if>
                    <c:forEach items="${pageInfo.navigatepageNums }" var="page_Num">
                        <c:if test="${page_Num == pageInfo.pageNum }">
                            <li class="active"><a href="#">${page_Num }</a></li>
                        </c:if>
                        <c:if test="${page_Num != pageInfo.pageNum }">
                            <li><a href="${APP_PATH }/user/selectAll?pn=${page_Num}">${page_Num}</a></li>
                        </c:if>
                    </c:forEach>
                    <c:if test="${pageInfo.hasNextPage }">
                        <li><a href="${APP_PATH }/user/selectAll?pn=${pageInfo.pageNum+1}" aria-label="Next"> <span
                                aria-hidden="true">&raquo;</span>
                        </a></li>
                    </c:if>
                    <li><a href="${APP_PATH }/user/selectAll?pn=${pageInfo.pages}">末页</a></li>
                </ul>
            </nav>
        </div>
    </div>
</div>
<script type="text/javascript">
	/*发送下载订单请求*/
	function downloadPass(license){
		if(confirm("确认下载？")){
			$.ajax({
				url:"${APP_PATH}/user/downloadPass",
				data:{"license":license},
				type:"POST",
					success:function(data){
						if(data=="OK"){
							alert("下载成功");
							window.location.reload();
						}else{
							alert("下载失败");
							window.location.reload();
						}
					}
			});
		}
	}
</script>
</body>
</html>